home *** CD-ROM | disk | FTP | other *** search
/ Pocket PC Game Programming / Pocket PC Game Programming.iso / source.exe / CH15 / GameLibrary / GameLibrary.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-03-05  |  4.8 KB  |  155 lines

  1. //////////////////////////////////////////////////////////////////////
  2. // Pocket PC Game Programming
  3. //
  4. // CGameLibrary Header File
  5. //
  6. // This file includes the CGameLibrary class definition.
  7. //
  8. //////////////////////////////////////////////////////////////////////
  9.  
  10. #pragma once
  11.  
  12. #include "stdafx.h"
  13.  
  14. //primary windows functions
  15. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow);
  16. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
  17.  
  18. //game library event functions
  19. extern "C" 
  20. {
  21.     BOOL GameInit(HINSTANCE hInst);
  22.     void GameStart(HWND hWnd);
  23.     void GameEnd();
  24.     void GameActivate(HWND hWnd);
  25.     void GameEvent();
  26.     void GamePaint(HWND hWnd);
  27.     void StylusDown(int x, int y);
  28.     void StylusMove(int x, int y);
  29.     void StylusUp(int x, int y);
  30.     
  31.     //*** New events for Chapter 11 ******************************
  32.     void ButtonPress(int iButtonID, POINT pt);
  33.     void ButtonRelease(int iButtonID, POINT pt);
  34.     //************************************************************
  35.  
  36. }
  37.  
  38. //color struct used by drawing routines
  39. struct COLOR
  40. {
  41.     BYTE Red;
  42.     BYTE Green;
  43.     BYTE Blue;
  44. };
  45.  
  46. //support functions
  47. void MsgBox(LPTSTR szMessage);
  48.  
  49. ////////////////////////////////////////////////////////////
  50. // CGameLibrary
  51. // Primary class for the game library
  52. ////////////////////////////////////////////////////////////
  53. class CGameLibrary  
  54. {
  55. protected:
  56.     //pointer to the CGameLibrary object
  57.     static CGameLibrary *pGameLib;
  58.  
  59.     TCHAR szWindowClass[40];
  60.     TCHAR szTitle[40];
  61.     BOOL bHibernate;
  62.     BOOL bFullscreen;
  63.     WORD wProgramIcon;
  64.     int iFrameRate;
  65.  
  66.     //GDI-specific
  67.     HINSTANCE hInstance;
  68.     HWND hWindow;
  69.  
  70.     //GAPI-specific
  71.     unsigned char *GAPIVidMem;
  72.     BOOL bGAPIDisplay;
  73.     GXDisplayProperties gxDisplay;
  74.  
  75.     //*** New variable for Chapter 11 ****************************
  76.  
  77.     GXKeyList gxKeys;
  78.  
  79.     //************************************************************
  80.  
  81. public:
  82.     //construct/destruct methods
  83.     CGameLibrary(HINSTANCE hInst, LPTSTR szNewWindowClass);
  84.     virtual ~CGameLibrary();
  85.  
  86.     //primary game library methods
  87.     BOOL Initialize(int nCmdShow);
  88.     LRESULT EventHandler(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
  89.     void Error(LPTSTR szError);
  90.     void Shutdown();
  91.     int ScreenWidth() { return GetSystemMetrics(SM_CXSCREEN); };
  92.     int ScreenHeight() { return GetSystemMetrics(SM_CYSCREEN); };
  93.  
  94.     //added in Chapter 12 **************************************************************
  95.     void PrintText(HDC hdc, LPCTSTR strText, int x, int y, COLORREF color, int iBkMode);
  96.     void FatalError(LPTSTR lpStr);
  97.     LPWSTR GetPath(TCHAR *filename = _T(""));
  98.     //**********************************************************************************
  99.  
  100.     //program instance methods
  101.     HINSTANCE GetInstance() { return hInstance; };
  102.     void SetInstance(HINSTANCE hInst) { hInstance = hInst; };
  103.  
  104.     //program window methods
  105.     HWND GetWindow() { return hWindow; };
  106.     void SetWindow(HWND hWnd) { hWindow = hWnd; };
  107.  
  108.     //window title methods
  109.     LPTSTR GetTitle() { return szTitle; };
  110.     void SetTitle(LPTSTR szNewTitle) { wcscpy(szTitle, szNewTitle); };
  111.  
  112.     //hibernate setting methods
  113.     BOOL GetHibernate() { return bHibernate; };
  114.     void SetHibernate(BOOL bSet) { bHibernate = bSet; };
  115.  
  116.     //fullscreen setting methods
  117.     BOOL GetFullscreen() { return bFullscreen; };
  118.     void SetFullscreen(BOOL bSet) { bFullscreen = bSet; };
  119.  
  120.     //icon setting methods
  121.     WORD GetIcon() { return wProgramIcon; };
  122.     void SetIcon(WORD wIcon) { wProgramIcon = wIcon; }; 
  123.  
  124.     //frame rate methods
  125.     int GetFrameRate() { return iFrameRate; };
  126.     void SetFrameRate(int iFrames) { iFrameRate = 1000/iFrames; };
  127.  
  128.     //GAPI functions and methods
  129.     BOOL G_Enabled() { return bGAPIDisplay; };
  130.     void G_SetDisplay(BOOL bSet) { bGAPIDisplay = bSet; };
  131.     void G_BeginDraw();
  132.     void G_EndDraw();
  133.     int GetXPitch() { return gxDisplay.cbxPitch; };
  134.     int GetYPitch() { return gxDisplay.cbyPitch; };
  135.     int GetBitsPerPixel() { return gxDisplay.cBPP; };
  136.     BOOL IsScreenFormat565() { return (gxDisplay.ffFormat | kfDirect565); };
  137.     unsigned char *G_GetVidMem() { return GAPIVidMem; };
  138.     BOOL G_ClearScreen(COLOR color);
  139.     int G_DrawPixel16(unsigned char *VidMem, int X, int Y, COLOR color);
  140.     void G_DrawSolidRect(unsigned char *VidMem, int iLeft, int iTop, int iRight, int iBottom, COLOR color);
  141.  
  142.     //return the static Class object
  143.     static CGameLibrary *GetObj(void) { return pGameLib; };
  144.  
  145.     //grant MsgBox access to the class object
  146.     friend void MsgBox(LPTSTR szMessage);
  147.  
  148.  
  149. };
  150.  
  151. //global CGameLibrary pointer
  152. inline CGameLibrary *GameLib() { return CGameLibrary::GetObj(); };
  153.  
  154.  
  155.